package com.gyg.service.impl;

import com.gyg.dao.IBlogDao;
import com.gyg.entity.Blog;
import com.gyg.service.IBlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * InnoDB free: 11264 kB 服务实现类
 * </p>
 *
 * @author 关注公众号：码猿编程日记
 * @since 2021-09-21
 */
@Service
public class BlogServiceImpl implements IBlogService {

    @Autowired
    IBlogDao iBlogDao;

    @Override
    public List<Blog> list() {
        return iBlogDao.list();
    }

    @Override
    public Blog getOne(Long id) {
        return iBlogDao.getOne(id);
    }

    @Override
    public Integer save(Blog blog) {
        Map<String,Object> param = new HashMap<>();
        param.put("userId",blog.getUserId());
        param.put("title",blog.getTitle());
        param.put("description",blog.getDescription());
        param.put("content",blog.getContent());
        param.put("created",blog.getCreated());
        param.put("status",blog.getStatus());
        return iBlogDao.save(param);
    }

    @Override
    public Integer update(Blog blog) {
        Map<String,Object> param = new HashMap<>();
        param.put("id",blog.getId());
        param.put("title",blog.getTitle());
        param.put("description",blog.getDescription());
        param.put("content",blog.getContent());
        return iBlogDao.update(param);
    }


    @Override
    public Integer delete(Long id)
    {

        return iBlogDao.delete(id);
    }

    @Override
    public Integer blogCount() {

        return iBlogDao.blogCount();
    }
}
